import Vue from 'vue'
import Router from 'vue-router'

import Login from '../views/Login'
import Main from '../views/Main'
import UserList from '../views/user/List'
import UserProfile from '../views/user/Profile'
import NotFound from '../views/NotFound'

Vue.use(Router);

export default new Router({
  //路由模式切换到history模式，URL中则没有#
  mode: 'history',
  routes: [
    {
      path: '/main/:name',
      component: Main,
      name: 'main',
      props: true,
      //嵌套路由
      children: [
        {
          //:id(类似restFul风格)@RequestMapping("/deleteBook/{bookId}")
          path: '/user/profile/:id',
          component: UserProfile,
          name: 'userProfile',
          //通过props解耦，组件用props接收参数
          props: true
        },
        {
          path: '/user/list',
          component: UserList,
          name: 'userList'
        }
      ]
    },
    {
      path: '/login',
      component: Login,
      name: 'login'
    },
    {
      path: '/goLogin',
      //重定向
      redirect: '/login'
    },
    {
      //匹配不到则走*
      path: '*',
      component: NotFound
    }
  ]
});
